package com.shenmazong.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @program: server-java-demo
 * @description: AtomicIntegerDemo
 * @author: 亮子说编程
 * @create: 2020-11-12 16:26
 **/
public class AtomicIntegerDemo extends Thread{
    private static AtomicInteger count = new AtomicInteger(0);

    //	private static volatile int count = 0;
    //每个线程加1000
    public static void addCount() {
        for(int i = 0; i < 1000; i++) {
//			count++;
            int ii = count.incrementAndGet();
        }
        System.out.println(count);
    }

    @Override
    public void run() {
        addCount();
    }

    public static void main(String[] args) {
        AtomicIntegerDemo[] vna = new AtomicIntegerDemo[10];
        for(int i = 0; i < 10; i++) {
            vna[i] = new AtomicIntegerDemo();
        }
        //10个线程
        for(int i = 0; i < 10; i++) {
            vna[i].start();
        }
    }
}
